<?php

namespace backend\models\rbac;

use yii\db\ActiveRecord;


class AuthItemChild extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%auth_item_child}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
        ];
    }

    /**
     * 获取角色列表
     * @param int $type
     * @return array|ActiveRecord[]
     */
    public static function getRoles($type=1,$filter='销售组长') {
        return static::find()
            ->select('sale_auth_item_child.parent')
            ->leftJoin('sale_auth_item', 'sale_auth_item_child.parent=sale_auth_item.name')
            ->where(['sale_auth_item.type'=>$type])
            ->andFilterWhere(['like', 'sale_auth_item.name', $filter])
            ->distinct()
            ->all();
    }
}
